package com.hissy.common.design.create.builder;

import com.alibaba.fastjson.JSON;

/**
 * Created by zhangyanfei on 2019/4/4.
 *
 * @author zhangyanfei
 * @date 2019/04/04
 */
public class BuilderMain {
    public static void main(String[] args) {
        /**
         * 创建者模式
         *
         * 需要一个Director 来组织创建过程
         */
        PersonDirector pd = new PersonDirector();
        AbstractPerson man = pd.constructPerson(new PersonManBuilder());
        System.out.println(JSON.toJSONString(man));
        AbstractPerson women = pd.constructPerson(new PersonWoManBuilder());
        System.out.println(JSON.toJSONString(women));

        EasyPersonBuilder easyPersonBuilder = new EasyPersonBuilder();

        // 简单的建造者模式
        AbstractPerson abstractPerson = easyPersonBuilder
            .buildBody("easy build body")
            .buildFoot("easy build foot")
            .buildHead("easy build head")
            .createPerson();

        System.out.println(JSON.toJSONString(abstractPerson));

    }
}
